package com.yuanhua.rabbitmq.helloworld;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

public class Producer {
    public static void main(String[] args) throws IOException, TimeoutException {
        ConnectionFactory connectionFactory = new ConnectionFactory();
        connectionFactory.setHost("");
        connectionFactory.setPort(222);
        connectionFactory.setUsername("55");
        connectionFactory.setPassword("52300");
        connectionFactory.setVirtualHost("/yuanhua");
        Connection connection = connectionFactory.newConnection();
        Channel channel = connection.createChannel();
        channel.queueDeclare("queue1",false,false,false,null);

        String msg = "yuanhua666";
        channel.basicPublish("", "queue1", null, msg.getBytes());
        channel.close();
        System.out.println("数据发送成功");
    }
}
